package com.cineplanet.dew.dao;

import java.util.ArrayList;
import java.util.List;

import javax.sql.DataSource;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.cineplanet.dew.exception.DAOExcepcion;
import com.cineplanet.dew.modelo.PeliculasPorCine;

public class PeliculaPorCineDAOImpl extends HibernateDaoSupport  implements PeliculaPorCineDAO {
	
	private DataSource dataSource;

	public void setDataSource(DataSource dataSource) {
		this.dataSource = dataSource;
	}
	
	@Override
	public List<PeliculasPorCine> listarTodosHorarios() throws DAOExcepcion {
		
		List<PeliculasPorCine> arreglo = new ArrayList<PeliculasPorCine>();
		try {
			arreglo = getHibernateTemplate().find("select distinct horaInicio, horaFin " +
												  "from PeliculasPorCine");
		} catch (Exception e) {

			throw new DAOExcepcion(e.getMessage());
		}
		return arreglo;
	}

	@Override
	public List<PeliculasPorCine> listarHorariosPorPelicula(int idPelicula) 
			throws DAOExcepcion {
		
		List<PeliculasPorCine> arreglo = new ArrayList<PeliculasPorCine>();
		try {
			arreglo = getHibernateTemplate().find("select distinct horaInicio, horaFin from PeliculasPorCine " +
												  "where id_pelicula = ?",
												  String.valueOf(idPelicula));
		} catch (Exception e) {
			throw new DAOExcepcion(e.getMessage());
		}
		return arreglo;
	}

	@Override
	public List<PeliculasPorCine> listarHorariosPorCine(int idCine) 
			throws DAOExcepcion {
		
		List<PeliculasPorCine> arreglo = new ArrayList<PeliculasPorCine>();
		
		try {
			arreglo = getHibernateTemplate().find("select distinct horaInicio, horaFin from PeliculasPorCine " +
												  "where id_cine = ?",
												  String.valueOf(idCine));
		} catch (Exception e) {
			throw new DAOExcepcion(e.getMessage());
		}
		return arreglo;
	}

}
